<template>
	<div id="FeedStockPieChart"></div>
</template>
<script setup="FeedStockPieChart">
	import { onMounted } from 'vue'
	import * as echarts from 'echarts'
	import BizFeedStocksApi from "@/api/feed/bizFeedStocksApi";

	let stockData = [];

	onMounted(() => {
		BizFeedStocksApi.getFeedStockInfo(null)
			.then(resp => {
				stockData = resp.map(obj =>({
					name:obj.typeName,
					value:obj.quantity
				}));
				draw()
			})
			.catch(resp => {
				console.log(resp);
			})
	})

	const draw = () =>{
		let Echarts = echarts.init(document.getElementById('FeedStockPieChart'))
		const option = {
			tooltip: {
				trigger: 'item'
			},
			legend: {
				top: '5%',
				left: 'center'
			},
			series: [
				{
					name: '库存量',
					type: 'pie',
					radius: ['40%', '70%'],
					avoidLabelOverlap: false,
					itemStyle: {
						borderRadius: 10,
						borderColor: '#fff',
						borderWidth: 2
					},
					label: {
						show: false,
						position: 'center'
					},
					emphasis: {
						label: {
							show: true,
							fontSize: '40',
							fontWeight: 'bold'
						}
					},
					labelLine: {
						show: false
					},
					data: stockData
					// data: [
					// 	{ value: 1048, name: 'Search Engine' },
					// 	{ value: 735, name: 'Direct' },
					// 	{ value: 580, name: 'Email' },
					// 	{ value: 484, name: 'Union Ads' },
					// 	{ value: 300, name: 'Video Ads' }
					// ]
				}
			]
		}
		// 绘制图表
		Echarts.setOption(option)
	}
</script>
